using System;
using Unity.VisualScripting;
using UnityEngine;
using Unity.Jobs;
using Unity.Collections;
using Unity.Burst;

public class BulletMove : MonoBehaviour
{

    public float m_fMoveSpeed;
    public TargetOp m_Target = new TargetOp();
    SmartTimer m_timer = new SmartTimer();
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        m_timer.DoReset(4);
        
    }
    //public struct JobMove : IJobFor
    //{
    //    [ReadOnly] public NativeArray<Vector3> trans;
    //    public NativeArray<Vector3> result;
    //    public float speed;
    //    public float fDelta;
    //    [BurstCompile]
    //    public void Execute(int index )
    //    {
    //        result[0] = trans[0] + trans[1] * speed * fDelta;
    //        //for ( int i = 0; i < 1000; ++ i )
    //        //    result[2] = trans[0] + trans[1] * speed * fDelta;
    //    }
    //}
    // Update is called once per frame
    //JobHandle m_handle;
    //NativeArray<Vector3> m_Pos;
    //NativeArray<Vector3> m_Result;
    void Update()
    {
        transform.position += m_Dir * m_fMoveSpeed * Time.deltaTime;
    }
    public static int m_BulletShow = 0;

    Vector3 m_Dir;
    float m_fDamage;
    public void DoInit(Vector3 start, Vector3 pos, float fDamage )
    {
        m_Dir = (pos - start).normalized;
        transform.position = start;
        gameObject.FaceVector2(pos);
        m_fDamage = fDamage;
        m_timer.DoReset(4);
        var trail = GetComponentInChildren<TrailRenderer>();
        trail.Clear();
        trail.emitting = true;
        ++m_BulletShow;
    }
    private void LateUpdate()
    {
        if (m_timer.DoUpdate())
        {
            OnClose();
            return;
        }
      
    }
 
 
    void OnClose()
    {
        var trail = GetComponentInChildren<TrailRenderer>();
        trail.emitting = false;
        gameObject.SetActive(false);
        --m_BulletShow;
    }
    private void OnDestroy()
    {
        
    }
}
